package com.sh.cloudrender.common.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

//0: pending;1: running; 2: release
@AllArgsConstructor
public enum EngineStateEnum {
    Pending(0, "pending"),
    Running(1, "running"),
    Release(2, "release"),
    Unknown(3, "unknown");

    @Getter
    private int code;

    @Getter
    private String desc;

    public static EngineStateEnum getByDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return Unknown;
        }

        for (EngineStateEnum stateEnum : EngineStateEnum.values()) {
            if (stateEnum.desc.equals(desc)) {
                return stateEnum;
            }
        }

        return Unknown;
    }
}
